import java.io.BufferedReader;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.HashMap;


public class ConvertImplment {

	private static BufferedReader in;
	private static PrintWriter implOut;
	/**
	 * @param args
	 */
	public static void main(String[] args) throws Exception{
		in = new BufferedReader(new FileReader("implements.txt"));
		implOut = new PrintWriter(new FileWriter("final_implements.txt"));
		Connection conn = ConnectionManager.openConnection();
		Statement st = conn.createStatement();
		ResultSet rs = st.executeQuery("select * from `class`");
		HashMap<String, Integer> pkmap = new HashMap<String, Integer>();
		while (rs.next()) {
			pkmap.put(rs.getString("cname"), rs.getInt("cid"));
		}
		String line = in.readLine();
		while (line != null) {
			String[] lineSegs = line.split("\\t");
			if (pkmap.get(lineSegs[1]) != null)
			implOut.println("insert into `class_impl_interface` (`cid`, `iid`) values (" + pkmap.get(lineSegs[0]) + ", " + pkmap.get(lineSegs[1]) + ");"); 
			line = in.readLine();
		}
		rs.close();
		st.close();
		conn.close();
		in.close();
		implOut.close();

	}

}
